//
//  TFMultimediaShutdown.swift
//  TalkfunSDKDemo
//
//  Created by 莫瑞权 on 2022/5/3.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit

open class TFMultimediaShutdown: UIView {

    @objc public let imageView = UIImageView()
    @objc public let gl = CAGradientLayer()
    let backgroundColorView = UIView()

    override init(frame: CGRect) {
        super.init(frame: frame)
       
        self.addSubview(self.backgroundColorView)
        // 圆角半径  能把一个下正文体,改成圆形
        self.backgroundColorView.layer.cornerRadius = 4.5
        

        //        超出主层边框的都会被裁减调用
        //        设置裁剪
        self.backgroundColorView.layer.masksToBounds = true
        
        self.backgroundColorView.layer.addSublayer(self.gl)
        
        self.addSubview(self.imageView)
    }
    required public init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    open override func layoutSubviews() {
        super.layoutSubviews()
        var imageViewW = 65
       
    if (UIDevice.current.userInterfaceIdiom == .phone)
    {
        imageViewW = 37;
    }
 
        let imageViewH = imageViewW;
        let imageViewX = (Int(self.frame.size.width) - imageViewW)/2;
        let imageViewY = (Int(self.frame.size.height) - imageViewH)/2;
        self.imageView.frame = CGRect(x: imageViewX, y: imageViewY, width: imageViewW, height: imageViewH)
  
    self.backgroundColorView.frame = self.bounds
    
    self.gl.frame = self.bounds
    
    self.gl.startPoint = CGPoint(x: 0, y: 0 )
    self.gl.endPoint = CGPoint(x: 1, y: 1 )

    self.layer.cornerRadius = 3;
    }
    @objc public func update(_ role:TalkfunRtcRole)
    {

        if(role == .roleSpadmin) {
        
            gl.colors = [UIColor(red: 116/255.0, green: 224/255.0, blue: 255/255.0, alpha: 1.0).cgColor, UIColor(red: 100/255.0, green: 158/255.0, blue: 255/255.0, alpha: 1.0).cgColor]
           
            
        }else{
            gl.colors = [UIColor(red: 255/255.0, green: 214/255.0, blue: 116/255.0, alpha: 1.0).cgColor, UIColor(red: 255/255.0, green: 177/255.0, blue: 100/255.0, alpha: 1.0).cgColor]
          
        }
        gl.locations = [0,1]
        
        
        
        if(role == .roleSpadmin){
           
            self.imageView.image =  UIImage.init(named: "HTLive.bundle/teacher")
        }else{
           
            self.imageView.image =  UIImage.init(named: "HTLive.bundle/xuesheng")
        }
    }

}
